import db from '../utils/dbconf';
import makeres from '../utils/res';
import { supermenu, adminmenu } from '../staticdata/menudata';
import { TABLE_NAME as AUTH_TABLE } from './auth/auth';
import { TABLE_NAME as AUTH_CONF_TABLE } from './auth/authconf';

const MENU_DICT = {
	999: supermenu,
	9: adminmenu,
};
export const getmenu = async ({}, res) => {
	const { level } = res.locals;
	return res.send(makeres.success(MENU_DICT[level]));
};

export const getauth = async ({}, res) => {
	const auth = await db.table(AUTH_TABLE).where({ inuse: 1 }).order('weight').select();
	for (let item of auth) {
		const price = await db.table(AUTH_CONF_TABLE).where({ auth_id: item.id }).select();
		Object.assign(item, { price });
	}
	return res.send(makeres.success(auth));
};

export default {
	getmenu,
};
